Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Programmer's Overview / Part 1 - Getting Started With QuickDraw GX
Chapter 2 - A Quick & Easy Sample Program


Drawing the Curve to a Macintosh Window

Now that you've created a curve shape, provided its geometry, specified its
pen width, colored it gray, and rotated it 45 degrees, it's ready to be drawn. Typically, on the Macintosh you draw shapes into windows that are located on monitor devices. Before you can draw the curve shape to a window, however, there are a few things you must know about the QuickDraw GX viewing architecture.

In its simplest form, the QuickDraw GX viewing architecture works as follows: The transform object of your shape contains a reference to a list of view port objects. Each view port belongs to a view group object, which groups view port objects and view device objects.

For the purposes of this example, you can think of a view port object as being associated with a Macintosh window and a view device object as being associa-
ted with a particular monitor. The view group object corresponds to a global coordinate space--for example, the "entire onscreen coordinate system." For complete information, see the "View-Related Objects" chapter of Inside Macintosh: QuickDraw GX Objects.

Figure 2-5 shows the relationship between the transform and view-
related objects.

Figure 2-5 Transforms and view-related objects

To draw your curve shape to a Macintosh window, you must first call the Macintosh Window Manager function GetNewWindow to create the window
and to provide a pointer to the corresponding window record.

Suppose you have done this, using a window pointer variable named theWindow. You can then create a view port object and associate it with the Macintosh window using the QuickDraw GX function GXNewWindowViewPort:

aViewPort = GXNewWindowViewPort(theWindow);
This function creates a new view port object, initializes its fields, associates
it with the window indicated by your theWindow variable, and returns a reference to it as the function result. Whenever the associated window is moved, resized, or zoomed, QuickDraw GX adjusts the properties of this
view port object to reflect the new position and size of the content portion
of the window.

Now, to draw your curve shape into this window, you must connect the curve shape's transform object to the new view port. You can do this using the GXSetShapeViewPorts function:

GXSetShapeViewPorts(aCurveShape, 1, &aViewPort);
This function call finds the transform object associated with your curve shape, and sets the value of its view port list property to point to the new view port object. (The value of 1 as the second parameter indicates how many view ports you want to install in the transform object's view port list--in this case, just 1.)

Finally, to draw the curve, you call the QuickDraw GX function GXDrawShape:

GXDrawShape(aCurveShape);
The GXDrawShape function

  1. analyzes the properties of the curve's shape object, style object, ink object, and transform object
  2. renders the resulting image in the view port referenced by the transform object, which in this case is associated with a Macintosh window

Figure 2-6 shows how the resulting curve shape appears when drawn.

Figure 2-6 The curve shape as drawn to a Macintosh window


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help